package com.zhu.ttwords.presenter;

import com.zhu.ttwords.bean.WordBean;
import com.zhu.ttwords.model.IStudyModel;
import com.zhu.ttwords.model.StudyModel;
import com.zhu.ttwords.view.activity.IStudyActivity;

import java.util.List;

/**
 * Created by KnightYe on 2015/4/3.
 * StudyPresenter.
 */
public class StudyPresenter {

    IStudyActivity activity;
    IStudyModel model;
    int currentMode = 0;
    int countRight = 0;

    public StudyPresenter(IStudyActivity activity) {
        this.activity = activity;
        this.model = new StudyModel();
    }

    public void showMenu() {
        activity.showMenu(currentMode);
    }

    public void initExam() {
        currentMode = IStudyActivity.MODE_EXAM;
        List<Object> mData;
        mData = model.loadExamWord();
        activity.initExamData(mData);
        activity.updateExamData(0);
    }

    public void initStudy() {
        currentMode = IStudyActivity.MODE_STUDY;
        List<Object> mData;
        mData = model.loadReviewWord();
        if(mData.size() > 0) {
            activity.initStudyData(mData, true);
        }else{
            mData = model.loadStudyWord();
            activity.initStudyData(mData, false);
        }
    }

    public void updatePageIndex(int i) {
        activity.updatePageIndex(i);
    }

    public void saveExamResult(WordBean bean,boolean result,int level) {
        model.saveWordResult( bean, result,level);
        if(result){
            countRight++;
            activity.updateExamData(countRight);
        }
    }

    public void saveStudyResult(WordBean bean, boolean result) {
        if (result) {
            countRight++;
            activity.updateExamData(countRight);
        }
    }
}
